import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';
import './permission';
import '@/styles/index.less';
// 注册全局配置
import { useAll } from '@/core/use';
// 下拉加载
import infiniteScroll from 'vue3-infinite-scroll-better';
// 注册自定义插件
import customPlugin from '@/utils/helper/plugin';
import 'ant-design-vue/dist/antd.less';
import 'viewerjs/dist/viewer.css';
import VueViewer from 'v-viewer';
import vue3TreeOrg from 'vue3-tree-org';
import 'vue3-tree-org/lib/vue3-tree-org.css';

// 注册qiankun
import { registerMicroApps, start } from 'qiankun';
import actions from './utils/qiankun-actions';

const app = createApp(App);

useAll(app);
customPlugin(app);

// 全局报错信息
app.config.errorHandler = (err, vm, info) => {
    console.log('发生报错', err);
    console.log('报错组件', vm);
    console.log('报错信息', info);
};

app.use(infiniteScroll).use(VueViewer).use(vue3TreeOrg).use(store).use(router).mount('#app');

// 注册微应用
registerMicroApps([
    {
        name: 'app1',
        entry: process.env.NODE_ENV === 'development' ? '//localhost:8001' : '/app1',
        container: '#subapp-container',
        activeRule: '/app1',
        props: {
            actions,
            getGlobalState: actions.getGlobalState,
            setGlobalState: actions.setGlobalState,
            mainStore: store
        }
    },
    {
        name: 'app2',
        entry: process.env.NODE_ENV === 'development' ? '//localhost:8002' : '/app2',
        container: '#subapp-container',
        activeRule: '/app2',
        props: {
            actions,
            getGlobalState: actions.getGlobalState,
            setGlobalState: actions.setGlobalState,
            mainStore: store
        }
    },
    {
        name: 'app3',
        entry: process.env.NODE_ENV === 'development' ? '//localhost:8003' : '/app3',
        container: '#subapp-container',
        activeRule: '/app3',
        props: {
            actions,
            getGlobalState: actions.getGlobalState,
            setGlobalState: actions.setGlobalState,
            mainStore: store
        }
    }
]);

// 启动 qiankun
start({
    sandbox: {
        strictStyleIsolation: true, // 开启严格样式隔离
        // experimentalStyleIsolation: true // 开启实验性样式隔离
    },
    prefetch: 'all',
    singular: true,
    urlRerouteOnly: true
});
